function ChangeToTable(reportTitle, printDatagrid, dataRow) {
    var tableString = '';
    var table = '';
    var frozenColumns = printDatagrid.datagrid("options").frozenColumns;  // 
    var columns = printDatagrid.datagrid("options").columns;    // 
    var nameList = new Array();
    var rows = dataRow;
    var footrows=[];    
    var queryParams=printDatagrid.datagrid("options").queryParams;

    if (rows == null || rows.length == 0) {
        rows = printDatagrid.datagrid("getRows"); // 
        if (rows == null || rows.length == 0) {
            $.messager.alert("提示",'没有要导出的数据！');
            return false;
        }
    }

    footrows = printDatagrid.datagrid("getFooterRows"); //
    if (footrows != null && footrows != undefined) {
        rows = $.merge(rows, footrows);
    }

    //
    if (typeof columns != 'undefined' && columns != '') {
        $(columns).each(function (index) {
            tableString += '<tr>';
            if (typeof frozenColumns != 'undefined' && typeof frozenColumns[index] != 'undefined') {
                for (var i = 0; i < frozenColumns[index].length; ++i) {
                    if (!frozenColumns[index][i].hidden) {          

                        tableString += '<th style="font-weight:bold;text-align:center; font-size:16px;background-color:gainsboro;border: 1px solid #7C7C7C;"';
                        tableString += ' width="' + frozenColumns[index][i].width + '"';
                        if (typeof frozenColumns[index][i].rowspan != 'undefined' && frozenColumns[index][i].rowspan > 1) {
                            tableString += ' rowspan="' + frozenColumns[index][i].rowspan + '"';
                        }
                        if (typeof frozenColumns[index][i].colspan != 'undefined' && frozenColumns[index][i].colspan > 1) {
                            tableString += ' colspan="' + frozenColumns[index][i].colspan + '"';
                        }
                        if (typeof frozenColumns[index][i].field != 'undefined' && frozenColumns[index][i].field != '') {
                            nameList.push(frozenColumns[index][i]);
                        }
                        tableString += '>' + frozenColumns[0][i].title + '</th>';
                    }
                }
            }
            for (var i = 0; i < columns[index].length; ++i) {
                if (!columns[index][i].hidden) {
                    tableString += '<th style="font-weight:bold;text-align:center; font-size:16px;background-color:gainsboro;border: 1px solid #7C7C7C;"';
                    tableString += ' width="' + columns[index][i].width + '"';
                    if (typeof columns[index][i].rowspan != 'undefined' && columns[index][i].rowspan > 1) {
                        tableString += ' rowspan="' + columns[index][i].rowspan + '"';
                    }
                    if (typeof columns[index][i].colspan != 'undefined' && columns[index][i].colspan > 1) {
                        tableString += ' colspan="' + columns[index][i].colspan + '"';
                    }
                    if (typeof columns[index][i].field != 'undefined' && columns[index][i].field != '') {
                        nameList.push(columns[index][i]);
                    }
                    tableString += '>' + columns[index][i].title + '</th>';
                }
            }
            tableString += '</tr>';
        });
    }
    //  
    for (var i = 0; i < rows.length; ++i) {
        tableString += '<tr>';
        for (var j = 0; j < nameList.length; ++j) {
            var e = nameList[j].field.lastIndexOf('_0');
            tableString += '<td style=" border: 1px solid #7C7C7C;';            
            if (nameList[j].align != 'undefined' && nameList[j].align != '') {
                tableString += ' text-align:' + nameList[j].align + ';"';
            }
            tableString += '>';
            if (e + 2 == nameList[j].field.length) {
                tableString += rows[i][nameList[j].field.substring(0, e)];
            }
            else {
                var v = rows[i][nameList[j].field];
                if (nameList[j].formatter instanceof Function) {
                    v = nameList[j].formatter(v, rows[i], i);
                }

                if(nameList[j].field=='datatime')
                {
                    v='\''+v;
                }

                if(v==null) v='';
                tableString += v;
            }
            tableString += '</td>';
        }
        tableString += '</tr>';
    }

    table='';
    table += '<table cellspacing="0" cellpadding="0" style="font-size:13px;">';
    table += '<tr><td style="font-weight:bold;text-align:center; font-size:16px;" colspan="' + nameList.length + '">' + reportTitle + '<td></tr>';
    table += tableString
    table += '</table>';
    return table;
}

function Export(fileName, reportTitle, exportGrid, dataRow, reportType) {

    var f = $('<form action="/BFSHandle.ashx?key=ExportReport" method="post" id="fm1"></form>');
    var i = $('<input type="hidden" id="txtContent" name="txtContent" />');
    var l = $('<input type="hidden" id="fileName" name="fileName" />');
    var t = $('<input type="hidden" id="reportType" name="reportType" />');
    var html = ChangeToTable(reportTitle, exportGrid, dataRow);

    //getExcelXML有一个JSON对象的配置，配置项看了下只有title配置，为excel文档的标题 
    //获取datagrid数据对应的excel需要的xml格式的内容  

    if(html=='') return false;
    
    html = encodeURI(html);
    i.val(html);
    i.appendTo(f);
    l.val(fileName);
    l.appendTo(f);
    t.val(reportType);
    t.appendTo(f);
    f.appendTo(document.body).submit();
    //document.body.removeChild(f);
}